package com.zhuzi.repository;

import com.zhuzi.entity.KzzAndStockEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface KzzAndStockEntityRepository extends JpaRepository<KzzAndStockEntity, String>, JpaSpecificationExecutor<KzzAndStockEntity> {
    List<KzzAndStockEntity> findByAmountGreaterThanEqualAndAmountLessThanEqual(BigDecimal amount, BigDecimal amount1);

    List<KzzAndStockEntity> findByAmountLessThanEqual(BigDecimal amount);

    @Transactional
    @Modifying
    @Query("delete from KzzAndStockEntity k")
    int deleteFirstBy();

    /**
     * 查找没有概念的可转债
     *
     * @return {@link List}<{@link KzzAndStockEntity}>
     */
    @Query(value = "SELECT * from kzz_base b WHERE not  exists  (SELECT bond_id from ths_stock_gn r WHERE b.cb_code=r.bond_id )", nativeQuery = true)
    List<KzzAndStockEntity> findNoGn();
}
